// src/router/index.js

import {createRouter, createWebHistory, createWebHashHistory} from 'vue-router'

const router = createRouter({
    history: createWebHashHistory(),  // hash 模式
    // history: createWebHistory(),  // history 模式
    routes: [
        {
            path: '/HelloWorld',
            name: 'HelloWorld',
            component: () => import(`../pages/HelloWorld.vue`),
            meta: {
                title: 'HelloWorld',
            },
        },
        {
            path: '/',
            redirect: '/HelloWorld',
        },
    ]
})

// 全局路由守卫
router.beforeEach((to, from, next)=>{
    // console.log(to, from)
    if (to.meta.title) {
        document.title = `vTab${to.meta.title}`;
    }
    next()
})

router.afterEach((to, from)=>{
    // console.log(to, from)
    // console.log('afterEach')
})

export default router